<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;
/**
 * 促销接口
 */
class PromGoods extends Api
{

    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\common\model\PromGoods();

    }

    /**
     * 活动页
     */
    public function huodong(){
        $banner = Db::name('banner')->where(['type' => 1])->select();

        $goods_where['starttime']  = array('lt',time());
        $goods_where['endtime']  = array('gt',time());
        $goods_where['status']  = 1;
        $goods_where['is_end']  = 0;

        $promList = $this->model->where($goods_where)->order('weigh desc')->select();
        foreach($promList as $k => $v){
            $promList[$k]['goodsList'] = $this->model->getGoodsList($v['id']);
        }

        $data = [
            'banner' => $banner,
            'promGoodsList' => $promList
        ];

        $this->success('',$data);
    }
}